package com.example.demos.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    private List<MessageInfo> list = new ArrayList<>();
    @RequestMapping("/publish")
     public boolean publish(MessageInfo messageInfo){
        System.out.println(messageInfo);
        if(!StringUtils.hasLength(messageInfo.getFrom())
        || !StringUtils.hasLength(messageInfo.getTo())
        || !StringUtils.hasLength(messageInfo.getMessage())){
            return false;
        }

        list.add(messageInfo);
        return true;
     }

     @RequestMapping("/getMessage")
    public List<MessageInfo> getMessage(){
        return list;
     }
}
